import store from '@/store/Store'
import request from '../axios/adminRequest'
const routes = [
  {
    path: '/',
    redirect: '/super-admin'
  },
  {
    path: '/login',
    name: 'adminLogin',
    component:()=>import('@/views/admin/adminLogin.vue')
  },
  {
    path: '/super-admin',
    name: 'superAdmin',
    component:()=>import('@/views/admin/adminIndex'),
    redirect:'/super-admin/set-users',
    beforeEnter:async ()=>{
      if(!store.state.adminStore.isLogin){
        if(localStorage.adminAccessKey){
          const data = await request.get('/is_login')
          if(data.code != 0){
            return { name :'adminLogin'}
          }
          store.commit('adminStore/changeLogin',true)
        }else{
          return { name :'adminLogin'}
        }
      }
    },
    children:[
      // {
      //   path:'data-center',
      //   name:'dataCenter',
      //   meta:{
      //     nav:'数据统计'
      //   },
      //   component:()=>import('@/views/admin/dataCenter/dataCenter')
      // },
      {
        path:'set-users',
        name:'setUsers',
        meta:{
          nav:'用户管理'
        },
        component:()=>import('@/views/admin/account/setUsers')
      },{
        path:'set-admins',
        name:'setAdmins',
        meta:{
          nav:'管理员设置'
        },
        component:()=>import('@/views/admin/system/setAdmins')
      },{
        path:'admin-logs',
        name:'adminLogs',
        meta:{
          nav:'管理员日志'
        },
        component:()=>import('@/views/admin/system/adminLogs')
      },{
        path:'site-config',
        name:'siteConfig',
        meta:{
          nav:'站点配置'
        },
        redirect: { name:'siteConfig.set-customer-service' },
        component:()=>import('@/views/admin/siteConfig/siteConfig'),
        children:[
          {
            path:'set-customer-service',
            name:'siteConfig.set-customer-service',
            component:()=>import('@/views/admin/siteConfig/setCustomerService')
          },{
            path:'set-tokens',
            name:'siteConfig.set-tokens',
            component:()=>import('@/views/admin/siteConfig/setTokens')
          }
        ]
      },{
        path:'set-notice',
        name:'setNotice',
        meta:{
          nav:'公告管理'
        },
        component:()=>import('@/views/admin/notice/setNotice')
      },{
        path:'set-empower',
        name:'setEmpower',
        meta:{
          nav:'授权管理'
        },
        component:()=>import('@/views/admin/empower/empower')
      },
    ]
  }
]

export default routes
